package user

import (
	"fmt"

	. "go-server/handler"

	"go-server/pkg/errno"

	"github.com/gin-gonic/gin"
	"github.com/lexkong/log"
)

// Create creates a new user account.
func Create(c *gin.Context) {

	var r CreateRequest

	var err error
	if err := c.Bind(&r); err != nil {
		SendResponse(c, errno.ErrBind, nil)
		return
	}

	log.Debugf("username is: [%s], password is [%s]", r.Username, r.Password)

	switch {
	case r.Username == "":
		err = errno.New(errno.ErrUserNotFound, fmt.Errorf("username can not found in db: xx.xx.xx.xx")).Add("This is add message.")
		SendResponse(c, err, nil)
		return
	case r.Password == "":
		err = fmt.Errorf("password is empty")
		SendResponse(c, err, nil)
		return
	}

	rsp := CreateReponse{Username: r.Username}
	SendResponse(c, nil, rsp)
}
